package com.study.designmodes.controller.pattern.strategy.lowlevel;

import com.study.designmodes.enums.BusinessCodeEnum;
import com.study.designmodes.request.BusinessObjectRequest;
import com.study.designmodes.service.strategy.ApiService;
import com.study.designmodes.service.strategy.StrategyService;
import com.study.designmodes.service.strategy.component.ApiFactory;
import com.study.designmodes.service.strategy.component.StrategyServiceFactory;
import org.springframework.web.bind.annotation.*;


/**
 * ApiController
 *
 * @author yyb8152
 * @since 20220402
 **/
@RestController
public class StrategyLowController {


    /**
     * @Description: 根据不同的枚举code通过策略bean工厂路由到（不同）具体的实现
     * @Param: code
     * @return:
     */
    @RequestMapping("/strategy/{code}")
    public String strategyMethod(@PathVariable("code") BusinessCodeEnum code) {
        ApiService apiService = ApiFactory.getApiServiceByCode(code);
        return apiService.invoke();

    }

    /**
     * @Description: 根据不同的Object对象通过策略bean工厂路由到不同的业务实现
     * @Param: [businessObjectRequest]
     * @return:
     */
    @PostMapping("/strategy")
    public String strategyChoose(@RequestBody BusinessObjectRequest businessObjectRequest) {
        StrategyService apiService = StrategyServiceFactory.getApiServiceByRequest(businessObjectRequest);
        return apiService.downloadFile(businessObjectRequest);

    }
}
